home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / Table / Sources / Selection.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  12.2 KB  |  411 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Selection.cpp
  4. //    Release Version:    $ ODF 2 $ 
  5. //
  6. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "Table.hpp"
  11.  
  12. // ----- TablePart Includes -----
  13.  
  14. #ifndef SELECTION_H
  15. #include "Selection.h"
  16. #endif
  17.  
  18. #ifndef PROXY_H
  19. #include "Proxy.h"
  20. #endif
  21.  
  22. #ifndef FRAME_H
  23. #include "Frame.h"
  24. #endif
  25.  
  26. #ifndef LINKING_H
  27. #include "Linking.h"
  28. #endif
  29.  
  30. #ifndef CONTENT_H
  31. #include "Content.h"
  32. #endif
  33.  
  34. #ifndef VIEW_H
  35. #include "View.h"
  36. #endif
  37.  
  38. // ----- ODF Includes -----
  39.  
  40. #ifndef FWFRAME_H
  41. #include "FWFrame.h"
  42. #endif
  43.  
  44. #ifndef FWRECT_H
  45. #include "FWRect.h"
  46. #endif
  47.  
  48. #ifndef FWUTIL_H
  49. #include "FWUtil.h"
  50. #endif
  51.  
  52. #ifndef FWPRESEN_H
  53. #include "FWPresen.h"
  54. #endif
  55.  
  56. #ifndef FWITERS_H
  57. #include "FWIters.h"
  58. #endif
  59.  
  60. #ifndef FWCONTXT_H
  61. #include "FWContxt.h"
  62. #endif
  63.  
  64. // ----- OS Layer -----
  65.  
  66. #ifndef FWODGEOM_H
  67. #include "FWODGeom.h"
  68. #endif
  69.  
  70. #ifndef FWEVENT_H
  71. #include "FWEvent.h"
  72. #endif
  73.  
  74. // ----- OpenDoc Includes -----
  75.  
  76. #ifndef SOM_ODShape_xh
  77. #include <Shape.xh>
  78. #endif
  79.  
  80. #ifndef SOM_ODTransform_xh
  81. #include <Trnsform.xh>
  82. #endif
  83.  
  84. #ifndef SOM_ODSession_xh
  85. #include <ODSessn.xh>
  86. #endif
  87.  
  88. //========================================================================================
  89. // RunTime Info
  90. //========================================================================================
  91.  
  92. #ifdef FW_BUILD_MAC
  93. #pragma segment odfTable
  94. #endif
  95.  
  96. FW_DEFINE_AUTO(CTableSelection)
  97.  
  98. //========================================================================================
  99. //    class CTableSelection
  100. //========================================================================================
  101.  
  102. //----------------------------------------------------------------------------------------
  103. //    CTableSelection::CTableSelection
  104. //----------------------------------------------------------------------------------------
  105.  
  106. CTableSelection::CTableSelection(Environment* ev, CTablePart* tablePart, CTablePartContent* content) :
  107.     FW_CSelection(ev, true, true),    // allow linking
  108.     fTablePart(tablePart),
  109.     fTableContent(content)
  110. {
  111.     fSelectionContent = FW_NEW(CTableSelectionContent, (ev, tablePart, content));
  112. }
  113.  
  114. //----------------------------------------------------------------------------------------
  115. //    CTableSelection::~CTableSelection
  116. //----------------------------------------------------------------------------------------
  117.  
  118. CTableSelection::~CTableSelection()
  119. {
  120. }
  121.  
  122. //----------------------------------------------------------------------------------------
  123. //    CTableSelection::GetSelectedContent
  124. //----------------------------------------------------------------------------------------
  125.  
  126. FW_CContent* CTableSelection::GetSelectedContent(Environment* ev)
  127. {
  128. FW_UNUSED(ev);
  129.     return fSelectionContent;
  130. }
  131.  
  132. //----------------------------------------------------------------------------------------
  133. //    CTableSelection::IsEmpty
  134. //----------------------------------------------------------------------------------------
  135.  
  136. FW_Boolean CTableSelection::IsEmpty(Environment* ev) const
  137. {
  138.     return fSelectionContent->GetSelectedProxy(ev) == NULL;
  139. }
  140.  
  141. //----------------------------------------------------------------------------------------
  142. //    CTableSelection::CloseSelection
  143. //----------------------------------------------------------------------------------------
  144.  
  145. void CTableSelection::CloseSelection(Environment* ev)
  146. {
  147. FW_UNUSED(ev);
  148. }
  149.  
  150. //----------------------------------------------------------------------------------------
  151. //    CTableSelection::ClearSelection
  152. //----------------------------------------------------------------------------------------
  153.  
  154. void CTableSelection::ClearSelection(Environment* ev)
  155. {
  156.     CTableProxy* proxy = fSelectionContent->GetSelectedProxy(ev);
  157.     if (proxy)
  158.     {
  159.         //--- Remove the proxy ---
  160.         proxy->DetachEmbeddedFrames(ev);
  161.         fTableContent->RemoveProxy(proxy);
  162.         InvalidateSelection(ev);
  163.     }
  164. }
  165.  
  166. //----------------------------------------------------------------------------------------
  167. //    CTableSelection::SelectAll
  168. //----------------------------------------------------------------------------------------
  169.  
  170. void CTableSelection::SelectAll(Environment* ev)
  171. {
  172. FW_UNUSED(ev);
  173. }
  174.  
  175. //----------------------------------------------------------------------------------------
  176. //    CTableSelection::Select
  177. //----------------------------------------------------------------------------------------
  178.  
  179. void CTableSelection::Select(Environment* ev, const CCell& cell)
  180. {
  181.     // Get the active frame
  182.     CTableFrame* activeFrame = (CTableFrame*)fTablePart->GetLastActiveFrame(ev);
  183.  
  184.     // Get the previous selected cell and proxy
  185.     CCell oldCell = fSelectionContent->GetCell();
  186.     CTableProxy* proxy = fTableContent->CellToProxy(oldCell);
  187.  
  188.     // Get the link manager so we can check for links
  189.     CTableLinkManager* linkMgr = (CTableLinkManager*)fTablePart->GetLinkManager(ev);
  190.     CTableLink* link = NULL;
  191.     CTableLinkSource* linkSource = NULL;
  192.  
  193.     // if the previous selected cell was containing a proxy then change its selected state
  194.     // and change its hilite
  195.     if (proxy)
  196.     {
  197.         proxy->SetSelectState(ev, FALSE);
  198.  
  199.         link = linkMgr->CellToLink(ev, oldCell);
  200.         if (link)
  201.             link->Select(ev, false);
  202.         linkSource = linkMgr->CellToSourceLink(ev, oldCell);
  203.         if (linkSource)
  204.             linkSource->Select(ev, false);
  205.     }
  206.     
  207.     // Erase the cell hilite
  208.     if (activeFrame)
  209.         activeFrame->GetTableView(ev)->ChangeHighlightState(ev, kODNoHighlight);
  210.  
  211.     // select the new cell
  212.     fSelectionContent->SetCell(cell);
  213.     
  214.     // get the proxy contained in the new selected cell
  215.     proxy = fTableContent->CellToProxy(cell);
  216.     
  217.     // if the new selected cell contains a proxy then change its selected state
  218.     // and hilite
  219.     if (proxy)
  220.     {
  221.         proxy->SetSelectState(ev, TRUE);
  222.  
  223.         link = linkMgr->CellToLink(ev, cell);
  224.         if (link)
  225.             link->Select(ev, true);
  226.         linkSource = linkMgr->CellToSourceLink(ev, cell);
  227.         if (linkSource)
  228.             linkSource->Select(ev, true);
  229.     }
  230.  
  231.     // Draw the cell hilite
  232.     if (activeFrame)
  233.         activeFrame->GetTableView(ev)->ChangeHighlightState(ev, activeFrame->HasSelectionFocus(ev) ? kODFullHighlight : kODDimHighlight);    
  234. }
  235.  
  236. //----------------------------------------------------------------------------------------
  237. //    CTableSelection::AcquireSelectionShape
  238. //----------------------------------------------------------------------------------------
  239.  
  240. ODShape* CTableSelection::AcquireSelectionShape(Environment* ev, ODFacet* facet, FW_CFrame* frame)
  241. {
  242.     FW_UNUSED(facet);
  243.     FW_UNUSED(frame);
  244.  
  245.     return fSelectionContent->AcquireSuggestedFrameShape(ev);
  246. }
  247.  
  248. //----------------------------------------------------------------------------------------
  249. //    CTableSelection::InvalidateSelection
  250. //----------------------------------------------------------------------------------------
  251.  
  252. void CTableSelection::InvalidateSelection(Environment* ev)
  253. {
  254.     FW_CAcquiredODShape aqShape = fSelectionContent->AcquireSuggestedFrameShape(ev);
  255.     GetPresentation(ev)->Invalidate(ev, aqShape);
  256. }
  257.  
  258. //----------------------------------------------------------------------------------------
  259. // CTableSelection::SelectProxy
  260. //----------------------------------------------------------------------------------------
  261.  
  262. void CTableSelection::SelectProxy(Environment* ev, CTableProxy* proxy)
  263. {
  264.     CCell cell = proxy->GetCell();
  265.     this->Select(ev, cell);
  266. }
  267.  
  268. //----------------------------------------------------------------------------------------
  269. // CTableSelection::GetSelectedCell
  270. //----------------------------------------------------------------------------------------
  271.  
  272. CCell CTableSelection::GetSelectedCell() const
  273. {
  274.     return fSelectionContent->GetCell();
  275. }
  276.  
  277. //----------------------------------------------------------------------------------------
  278. //    CTableSelection::IsMouseInDraggableItem
  279. //----------------------------------------------------------------------------------------
  280.  
  281. FW_Boolean CTableSelection::IsMouseInDraggableItem(Environment* ev, 
  282.                                                 FW_CFrame* frame, 
  283.                                                 const FW_CMouseEvent& theMouseEvent, 
  284.                                                 FW_Boolean inBackground)
  285. {
  286.     FW_UNUSED(inBackground);
  287.  
  288.     CCell cell;
  289.     ETableLoc tl = fTableContent->HitTest(ev, theMouseEvent, frame->GetContentView(ev), cell);
  290.     
  291.     return (tl == kTLCell && fTableContent->CellToProxy(cell) != NULL);
  292. }
  293.  
  294. //----------------------------------------------------------------------------------------
  295. // CTableSelection::UpdateSelectionOnMouseDown
  296. //----------------------------------------------------------------------------------------
  297.  
  298. void CTableSelection::UpdateSelectionOnMouseDown(Environment* ev, 
  299.                                             const FW_CMouseEvent& mouseEvent,
  300.                                             ODFacet* embeddedFacet,
  301.                                             FW_Boolean inEmbeddedFrameBorder,
  302.                                             FW_Boolean inBackground)
  303. {
  304.     FW_UNUSED(inBackground);
  305.  
  306.     CTableFrame* tableFrame = (CTableFrame*)FW_CFrame::ODtoFWFrame(ev, mouseEvent.GetFacet(ev)->GetFrame(ev));
  307.     
  308.     if (tableFrame->GetTableView(ev)->IsGridShown(ev))
  309.     {
  310.         FW_Boolean select = FALSE;
  311.         CCell cell;
  312.         
  313.         if (inEmbeddedFrameBorder)
  314.         {
  315.             FW_MProxy* proxy = tableFrame->GetProxy(ev, embeddedFacet->GetFrame(ev));
  316.             FW_ASSERT(proxy);
  317.             
  318.             cell = ((CTableProxy*)proxy)->GetCell();    
  319.             select = TRUE;
  320.         }
  321.         else
  322.         {
  323.             ETableLoc tl = fTableContent->HitTest(ev, mouseEvent, tableFrame->GetContentView(ev), cell);    
  324.             select = (tl == kTLCell && cell != GetSelectedCell());
  325.         }
  326.         
  327.         if (select)
  328.             Select(ev, cell);
  329.     }
  330. }
  331.  
  332. //----------------------------------------------------------------------------------------
  333. //    CTableSelection::CanPasteAsLink
  334. //---------------------------------------------------------------------------------------
  335.  
  336. FW_Boolean CTableSelection::CanPasteAsLink(Environment* ev, ODPasteAsMergeSetting& setting,
  337.                                             ODStorageUnit* su)
  338. {
  339. #ifndef FW_DEBUG
  340. FW_UNUSED(ev);
  341. #endif
  342. FW_UNUSED(su);
  343.     setting = kODPasteAsEmbedOnly;    // table has no content to merge
  344.  
  345.     // we shouldn't be here at all unless the selection is empty
  346.     
  347.     FW_ASSERT(this->IsEmpty(ev));
  348.     return TRUE;
  349. }
  350.  
  351. //----------------------------------------------------------------------------------------
  352. //    CTableSelection::IsSelectionLinkable
  353. //----------------------------------------------------------------------------------------
  354.  
  355. FW_Boolean CTableSelection::IsSelectionLinkable(Environment* ev)
  356. {
  357.     FW_Boolean result = fAllowLinkSource;
  358.  
  359.     if (fAllowLinkSource)
  360.     {
  361.         // make sure the cell is not a link destination
  362.         CTableLinkManager* linkMgr = (CTableLinkManager*)fTablePart->GetLinkManager(ev);
  363.         if (linkMgr->CellToLink(ev, this->GetSelectedCell()))
  364.             result = FALSE;
  365.     }
  366.  
  367.     return result;
  368. }
  369.  
  370. //----------------------------------------------------------------------------------------
  371. //    CTableSelection::DoFindLinkSource
  372. //----------------------------------------------------------------------------------------
  373.  
  374. FW_CLinkSource* CTableSelection::DoFindLinkSource(Environment* ev)    // Override
  375. {
  376.     CTableLinkManager* linkMgr = (CTableLinkManager*)fTablePart->GetLinkManager(ev);
  377.     return linkMgr->CellToSourceLink(ev, fSelectionContent->GetCell());
  378. }
  379.  
  380. //----------------------------------------------------------------------------------------
  381. //    CTableSelection::GetLinkDestination
  382. //----------------------------------------------------------------------------------------
  383.  
  384. FW_CLinkDestination* CTableSelection::GetLinkDestination(Environment* ev, FW_Boolean& multipleLinks)
  385. {
  386. FW_UNUSED(multipleLinks);
  387.     // check whether the selected part is in a link destination
  388.     CTableLinkManager* linkMgr = (CTableLinkManager*)fTablePart->GetLinkManager(ev);
  389.     return linkMgr->CellToLink(ev, this->GetSelectedCell());
  390. }
  391.  
  392. //----------------------------------------------------------------------------------------
  393. //    CTableSelection::GetSavedLinkSpecID
  394. //----------------------------------------------------------------------------------------
  395. ODUpdateID CTableSelection::GetSavedLinkSpecID(Environment* ev)
  396. {
  397.     // Return the link spec ID saved in the currently selected proxy
  398.     CTableProxy* selectedProxy = fSelectionContent->GetSelectedProxy(ev);
  399.     return selectedProxy->GetLinkSpecID();
  400. }
  401.  
  402. //----------------------------------------------------------------------------------------
  403. //    CTableSelection::SaveLinkSpecID
  404. //----------------------------------------------------------------------------------------
  405. void CTableSelection::SaveLinkSpecID(Environment* ev, ODUpdateID linkSpecID)
  406. {
  407.     // Save the link spec ID in the currently selected proxy
  408.     CTableProxy* selectedProxy = fSelectionContent->GetSelectedProxy(ev);
  409.     selectedProxy->SetLinkSpecID(linkSpecID);
  410. }
  411.